commonlibsse_ng\re\b/
BGSEntryPointFunction.rs

1use core::ffi::{c_char, c_void};
2use core::ptr::NonNull;
3
4use crate::re::TESObjectREFR::TESObjectREFR;
5
6#[commonlibsse_ng_derive_internal::ffi_enum]
7#[repr(u32)]
8#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
9pub enum ENTRY_POINT_FUNCTION {
10    NullFunction = 0,
11    SetValue = 1,
12    AddValue = 2,
13    MultiplyValue = 3,
14    AddRangeToValue = 4,
15    AddActorValueMult = 5,
16    AbsoluteValue = 6,
17    NegativeAbsoluteValue = 7,
18    AddLeveledList = 8,
19    AddActivateChoice = 9,
20    SelectSpell = 10,
21    SelectText = 11,
22    SetToActorValueMult = 12,
23    MultiplyActorValueMult = 13,
24    MultiplyOnePlusActorValueMult = 14,
25    SetText = 15,
26}
27
28#[commonlibsse_ng_derive_internal::ffi_enum]
29#[repr(u32)]
30#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
31pub enum ENTRY_POINT_FUNCTION_TYPE {
32    Value = 0,
33    AddLeveledList = 1,
34    AddActivateChoice = 2,
35    Null = 3,
36    SelectSpell = 4,
37    SelectText = 5,
38    SetText = 6,
39}
40
41type Function =
42    fn(repr: TESObjectREFR, type_: ENTRY_POINT_FUNCTION_TYPE, u8, *mut *mut c_void, *mut c_void);
43
44#[repr(C)]
45#[derive(Debug)]
46pub struct EntryPointFunction {
47    name: *const c_char,              // 0x00
48    type_: ENTRY_POINT_FUNCTION_TYPE, // 0x08
49    pad0C: u32,                       // 0x0C
50    function: Function,               // 0x10
51}
52const _: () = assert!(core::mem::size_of::<EntryPointFunction>() == 0x18);
53
54impl EntryPointFunction {
55    /// Gets `Self` from `ENTRY_POINT_FUNCTION`. for SE, VR.
56    ///
57    /// # Panics
58    /// - If Runtime is AE then panic.
59    #[commonlibsse_ng_derive_internal::relocate(
60        cast_as = "*mut EntryPointFunction",
61        default = "None",
62        id(se = 369178, ae = 0)
63    )]
64    #[inline]
65    pub fn from_entry_point_function(
66        entry_point_function: ENTRY_POINT_FUNCTION,
67    ) -> Option<NonNull<EntryPointFunction>> {
68        |as_type: AsType| unsafe { NonNull::new(as_type.add(entry_point_function as usize)) }
69    }
70}
71
72/// Gets argument count from `ENTRY_POINT_FUNCTION_TYPE`. for SE, VR.
73///
74/// # Panics
75/// If Runtime is AE then panic.
76#[commonlibsse_ng_derive_internal::relocate(
77    cast_as = "*mut u32",
78    default = "None",
79    id(se = 369210, ae = 0)
80)]
81#[inline]
82pub fn get_argument_count(entry_point_function_type: ENTRY_POINT_FUNCTION_TYPE) -> Option<u32> {
83    |as_type: AsType| unsafe { as_type.add(entry_point_function_type as usize).as_ref().copied() }
84}